<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ include file="../Main/top.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="/WEB-INF/CustomTag" prefix="customTag"%>
<script type="text/javascript" src="MajorFileSrcCate.js"></script>
<script type="text/javascript">
	$(document).ready( function() {
		majorFileCateParentIdChange();
		isPreCategoryClick();
		queryMajorList();

		//如果为预置分类隐藏专业选项
		if(${majorFileSrcCate.isPreCategory}==1){
			$("#majorIdLine").hide();
		}
		//除根分类外隐藏预置设置选项
		if(${majorFileSrcCate.majorFileCateParentId}!=-1){
			$("#isPreCategoryLine").hide();
		}
	});
	
	//父分类ID改变激活事件
	function majorFileCateParentIdChange() {
		$("#majorFileCateParentId").change(function() {
			if ($("#majorFileCateParentId").attr("value") != -1) {
				getParentCateIsPre();
			} else if ($("#majorFileCateParentId").attr("value") == -1) {
				$("#isPreCategory0").attr("checked", false)
				$("#isPreCategory1").attr("checked", false)
				$("#isPreCategoryLine").show();
				$("#majorIdLine").show();
				$("#majorIdNull").attr("selected",true);
				$("#depth").attr("value",1);
			}
		});
	}

	//获取是否为预置分类并根据其设置当前分类值
	function getParentCateIsPre(){
		var majorFileCateParentId = document.getElementById("majorFileCateParentId").value;
		if(majorFileCateParentId!=""){
			$.post(
					"../AjaxResultData/checkParentCateIsPre.action",
					{"majorFileSrcCate.majorFileCateId":majorFileCateParentId},
					function(data){
						var isNotUsedData = eval("("+data.isNotUsedData+")");
						if(isNotUsedData[0].isNotUsed==0){
							$("#isPreCategory0").attr("checked", true);
							$("#isPreCategoryLine").hide();
							$("#majorIdLine").hide();
						}else if(isNotUsedData[0].isNotUsed==1){
							$("#isPreCategory1").attr("checked", true);
							$("#isPreCategoryLine").hide();
							$("#majorIdNull").attr("selected",true);
							$("#majorIdLine").hide();
						}
						$("#majorId").attr("value",isNotUsedData[0].cateId);
						$("#depth").attr("value",(parseInt(isNotUsedData[0].parentDepth)+1));
						//alert($("#majorId option:selected").attr("value"));
					},
					"json"
			);
		}
	}
	
	function isPreCategoryClick(){
		$("#isPreCategory1").click(function(){
			$("#majorIdNull").attr("selected",true);
			$("#majorIdLine").hide();
		});
		$("#isPreCategory0").click(function(){
			$("#majorIdLine").show();
		});
	}
	function queryMajorList(){
		$.post(
			"../AjaxResultData/listAllMajor.action",
			function(data){
				var majorData = eval("("+data.majorData+")");
				for(var i = 0; i<majorData.length; i++){
					if(${majorFileSrcCate.majorId} == majorData[i].majorId){
						$('#majorId').append("<option value='"+majorData[i].majorId+"' selected='selected'>"+majorData[i].majorName+"</option>");
					}else{
						$('#majorId').append("<option value='"+majorData[i].majorId+"'>"+majorData[i].majorName+"</option>");
					}
				}
			}
		);
	}
</script>
<div class="function_title"><span class="t2"><img src="../images/dqwz.gif">当前位置：编辑分类信息</span></div>
<div class="function_content">

<div class="addItem"><img src="../images/return_icon.png"><a href="listMajorFileSrcCate.action?intercept=1">返回列表</a></div>

<span class="important_info">注：带*项为必填信息!</span>
<form action="updateMajorFileSrcCate.action" method="post" id="demo" >
<s:hidden name="majorFileSrcCate.majorFileCateId"></s:hidden>
<input type="hidden" name="majorFileSrcCate.depth" id="depth" value="<s:property value='majorFileSrcCate.depth'/>"> 
  <table width="100%" border="0" cellpadding="0" cellspacing="0" class="loginTable">
    <tr>
      <td width="14%" align="right" class="leftBg"><span class="important_info">*</span>分类名称：</td>
      <td width="86%"><s:textfield name="majorFileSrcCate.majorFileCateName" id="majorFileSrcCate.majorFileCateName"></s:textfield></td>
    </tr>
    <tr>
      <td align="right" class="leftBg"><span class="important_info">*</span>所属父分类：</td>
      	<td>
<customTag:treeSelector majorFileCateId="${majorFileSrcCate.majorFileCateParentId}" type="majorFileSrcCate" selectName="majorFileCateParentId" notNeedValidation="false" target="false"></customTag:treeSelector>
		</td>
    </tr>
    <tr id="isPreCategoryLine">
      <td align="right" class="leftBg"><span class="important_info">*</span>是否为预置分类：</td>
      <td>
<s:if test="%{majorFileSrcCate.isPreCategory==1}">
<input type="radio" name="majorFileSrcCate.isPreCategory" value="1" class="no_border" id="isPreCategory1" checked="checked">是
<input type="radio" name="majorFileSrcCate.isPreCategory" value="0" class="no_border" id="isPreCategory0">否
</s:if>
<s:elseif test="%{majorFileSrcCate.isPreCategory==0}">
<input type="radio" name="majorFileSrcCate.isPreCategory" value="1" class="no_border" id="isPreCategory1" >是
<input type="radio" name="majorFileSrcCate.isPreCategory" value="0" class="no_border" id="isPreCategory0" checked="checked">否
</s:elseif>
<span id="errMsg"></span>
</td>
    </tr>
    <tr id="majorIdLine">
      <td align="right" class="leftBg"><span class="important_info">*</span>所属专业：</td>
      <td>
		<select name="majorFileSrcCate.majorId" id="majorId">
			<option value="" id="majorIdNull">--未选择--</option>
		</select>
	</td>
    </tr>
    <tr>
      <td align="right">&nbsp;</td>
      <td>
        <input type="submit" name="submit" id="submit" value="提交" class="deal_button">
      </td>
    </tr>
  </table>
</form>

</div>

<%@ include file="../Main/bottom.jsp"%>
